<?php

class Filemanager_UploadController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout()->disableLayout();
    }

    public function indexAction()
    {
        $form = new Filemanager_Form_Upload();
	
	if($this->getRequest()->isPost() && $form->isValid($_POST))
	{
	    
	    $adapter = new Zend_File_Transfer_Adapter_Http();

	    $adapter->setDestination('images/');

	    $adapter->receive();

	    
	    
	}
	
	$this->view->form = $form;
    }

    public function filetreeAction()
    {
        $this->listDir(APPLICATION_PATH . '/../public/images');
	
	/* Das ist der korrekte Weg, ein Verzeichnis zu durchlaufen. */
//	while (false !== ($file = readdir($dirHandle))) {
//	    if(is_file($file))
//	    {
//		echo $file;
//	    }
//	}
    }
    
    public function listDir($path)
    {
	$dirHandle = opendir($path);
	echo $path;
	while (false !== ($file = readdir($dirHandle))) 
	{
//	    echo $path.DIRECTORY_SEPARATOR.$file;
	    if(substr($file, 0, 1) != '.')
	    {
		if(is_dir($path.DIRECTORY_SEPARATOR.$file))
		{
		    echo '<a href="">'.$file.'</a>';
		}
	    
		if(is_file($path.DIRECTORY_SEPARATOR.$file))
		{
		    echo $file;
		}
		echo "<br>";
	    }
	    
	}
    }


}



